// pages/ryshop/ryshop.js
/**百宝箱*/
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        smallmodel: true,
        siteUrl   : app.globalData.siteUrl,
        openDetail: true,
        detail    : [],
        tupian    : app.globalData.imgUrl
    },

    /**显示物品详情*/
    showDetail(e) {
        let self   = this;
        let list   = this.data.list;
        let index  = e.currentTarget.dataset.index;
        let detail = list[index];
        self.setData({
            detail    : detail,
            openDetail: false
        })
    },


    /**关闭物品详情*/
    closeDetail() {
        this.setData({openDetail: true})
    },

    /**使用物品*/
    useGoods(e) {
        console.log(e);
        let self          = this;
        let id            = e.currentTarget.dataset.id;
        let type          = e.currentTarget.dataset.type;
        let userInfo      = app.globalData.userInfo;
        let use_goods_url = 'Goods/useGoods';
        app.getdata.fetchApi(use_goods_url, {
            session_key: userInfo.token,
            id         : id,
            type       : type
        }).then(res => {
            if (res.status === 1) {
                if (res.data['logo']) {
                    self.setData({smallmodel: false, open_list: res.data})

                }
                self.getUserGoodsList();
                //
                self.closeDetail();
                //self.setData({list: res.data});
            }
        })
    },

    /**
     * 关闭开宝箱详情
     */
    closeOpenList() {
        let self=this;
        self.setData({smallmodel: true, open_list: []});

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log('__________________');
        let self = this;
        self.getUserGoodsList();
    },


    getUserGoodsList() {
        let self           = this;
        let user_goods_url = 'Goods/userGoodsList';
        let userInfo       = app.globalData.userInfo;
        app.getdata.fetchApi(user_goods_url, {session_key: userInfo.token}).then(res => {
            if (res.status === 1) {
                self.setData({list: res.data});
            } else {
                self.setData({list: []});
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})